< previous page page_295 next page >

Page 295
is zero (thus, thisbyte values of 0F will actually appear as 000F). Tutorial 3 demonstrates how the AND operation is used here to test whether the high nibble is zero.
Private Function GetDataString(Address As Long, Bytes As Long) _
As String
   Dim thisbyte As Byte
   Dim offset As Integer
   Dim result$

   For offset = 0 To Bytes - 1
      ' We get the contents of the byte at address+offset
      Call RtlMoveMemory(VarPtr(thisbyte), Address + offset, 1)

      ' If it's 0-15, add a zero.
      If (thisbyte And &HFO) = 0 Then result$ = result$ & "0"
      result$ = result$ & Hex$(thisbyte) & " "
   Next offset

   GetDataString = result$
End Function
The Command1_Click routine uses the GetDataString function to retrieve the actual memory contents for each variable. The VarPtr function is a poorly documented Visual Basic function that retrieves the address of a variable in memory. You'll use this function often when working with API and DLL calls. The LenB function returns the size of the variable in memory for most types of variables. (For variants, it returns the size of the data contained in the variant rather than the size of the variant itself. For strings, it returns the length of the string.)
Private Sub Commandl_Click()
   Dim newline As String
   Dim x&
   List1.Clear

   List1.AddItem "Integer: " & GetDataString(VarPtr(I), LenB(I))
   List1.AddItem "Long: " & GetDataString(VarPtr(L), LenB(L))
   List1.AddItem "Single (Float): " & GetDataString(VarPtr(F), LenB(F))
   List1.AddItem "Double: " & GetDataString(VarPtr(D), LenB(D))
   List1.AddItem "Currency: " & GetDataString(VarPtr(C), LenB(C))
   List1.AddItem "Byte: " & GetDataString(VarPtr(b), LenB(b))
   List1.AddItem "Variant: " & GetDataString(VarPtr(V), 16)
   List1.AddItem "String: " & GetDataString(VarPtr(S), LenB(S))

 
< previous page page_295 next page >